﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Security.AccessControl;

namespace Dir
{
    public class Search
    {
        private List<string> filePathList = new List<string>();
        private List<string> directoryPatnList = new List<string>();

        public void GetFile(string path, string ext)
        {
            string s = "*" + ext;
            DirectoryInfo directory = new DirectoryInfo(path);
            FileInfo[] dir = directory.GetFiles(s);

            foreach (FileInfo d in dir)
            {
                filePathList.Add(d.FullName);
            }
        }

        public void GetDirectory(string path)
        {
            DirectoryInfo directory = new DirectoryInfo(path);
            try
            {
                foreach (DirectoryInfo d in directory.GetDirectories("*"))
                {
                    directoryPatnList.Add(d.FullName);
                    GetDirectory(d.FullName);
                }
            }
            catch (Exception e)
            {
                directoryPatnList.RemoveAt(directoryPatnList.Count - 1);
            }
        }

        public List<string> GetDirectoryList()
        {
            return directoryPatnList;
        }

        public List<string> GetFilePathList()
        {
            return filePathList;
        }
    }
}